package com.biz.primus.management.thirdlogin.init;

import com.biz.primus.account.service.AuthInitializeService;
import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.model.sso.auth.vo.GrantedAuthority;
import com.biz.primus.model.sso.auth.vo.MenuGroupVO;
import com.biz.primus.model.sso.auth.vo.MenuItemVO;
import com.biz.primus.model.sso.auth.vo.ResourceVO;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.google.common.collect.Lists.newArrayList;

/**
 * Created by jun.liu on 9/19/17.
 */
@Service
public class InitManager {

    private final AuthInitializeService authInitializeService;

    @Autowired
    public InitManager(AuthInitializeService authInitializeService) {
        this.authInitializeService = authInitializeService;
    }

    @PostConstruct
    public void setup() {

        List<MenuGroupVO> menuGroups = newArrayList();
        MenuGroupVO menuGroupVO = new MenuGroupVO("MANAGEMENT_DEMO", "示例管理", "各种示例管理", "fa fa-cogs", CommonStatus.ENABLE, 999);

        List<MenuItemVO> menuItems = newArrayList();

        /**============START===========*/
        MenuItemVO thirdloginManageMenuItemVO = new MenuItemVO("MANAGEMENT_ADV", "统一账户管理", "统一账户管理", "fa fa-list", "advertisement/adv/list.do", CommonStatus.ENABLE, 2);

        List<ResourceVO> thirdloginResources = newArrayList();
        thirdloginResources.add(new ResourceVO("MANAGEMENT_THIRDLOGIN_BINDING", "绑定", "绑定", CommonStatus.ENABLE, new GrantedAuthority("OPT_THIRDLOGIN_BINDING"), 3));
        thirdloginResources.add(new ResourceVO("MANAGEMENT_THIRDLOGIN_UNBINDING", "解绑", "解绑", CommonStatus.ENABLE, new GrantedAuthority("OPT_THIRDLOGIN_UNBINDING"), 4));

        thirdloginManageMenuItemVO.setResources(thirdloginResources);
        /**============END===========*/


        menuItems.add(thirdloginManageMenuItemVO);

        menuGroupVO.setMenuItems(menuItems);
        menuGroups.add(menuGroupVO);
        authInitializeService.registerMenu(menuGroups);
    }
}
